<template>
  <div>
    <!-- <span style="color: cadetblue; margin-right: 1000px;" @click="back">返回</span> -->
    <el-button type="success" size="mini" style="margin-right: 1000px;margin-bottom: 10px;" @click="back">返回</el-button>
    <el-row>
      <el-col :span="14">
        <div class="block">
          <el-carousel trigger="click" height="280px">
            <el-carousel-item v-for="item in this.otherImgList" :key="item">
              <el-image style="width:100%;height: 100%; " :src="item">
              </el-image>
            </el-carousel-item>
          </el-carousel>
        </div>
      </el-col>

      <el-col :span="7" style="text-align: left; padding:40px;background: #fcfcfc;">
        <h1 style="font-weight: bold;color: #303133; font-size: 18px;">
          标题：<span style="color: #409EFF;font-size: 20px;"> {{ title }}</span>
        </h1>

        <h1 style="font-weight: bold;color: #303133; font-size: 18px;">
          价格：<span style="color: #F56C6C;font-size: 20px;">
            {{ price }}￥</span>
        </h1>
        <h1 style="font-weight: bold;color: #303133; font-size: 18px;">
          出发地-结束地：<span style="color: #67C23A;font-size: 20px;">
            {{ startSite }}-{{ endSite }}</span>
        </h1>
        <br />
        <el-button size="medium" type="success" @click="toSpotOrder()">路线预订</el-button>
        <span style="margin-left: 10px;">
          <i class="el-icon-star-on" v-if="isCollect" @click="collected"></i>
          <i class="el-icon-star-off" v-else @click="collected"></i>
        </span>
      </el-col>
    </el-row>

    <el-row style="width: 100%; display: block; float: left; margin-top: 30px;margin-bottom: 30px;">
    </el-row>

    <el-row>
      <el-col :span="22">
        <div class="grid-content bg-purple">
          <el-card class="box-card" style="width: 99%;padding: 15px;">
            <div slot="header" class="clearfix">
              <span style="font-weight: bold; color: green; font-size: 25px;"><i class="el-icon-notebook-2"></i>
                路线简介</span>
            </div>
            <div style="display: flex;flex-direction: column;">
              <div class="item">
                <p class="textHead">行程时间</p>
                <b class="textBody">{{ startTime }} 到 {{ endTime }}</b>
              </div>
              <div class="item">
                <p class="textHead">天数</p>
                <b class="textBody">{{ day }} 天</b>
              </div>
              <div class="item">
                <p class="textHead">路线介绍 <i class="el-icon-right"></i></p>
                <!-- <b class="textBody">{{ intro }}</b> -->
                <el-collapse v-model="activeName" accordion>
                  <el-collapse-item title="" name="1">
                    <div class="textBody" style="margin-right: 10px;">{{intro}}</div>
                  </el-collapse-item>
                </el-collapse>
              </div>
            </div>
          </el-card>
        </div>
      </el-col>

      <el-col :span="22">
        <div class="grid-content bg-purple">
          <el-card class="box-card" style="width: 99%;padding: 10px;">
            <div slot="header" class="clearfix">
              <span style="font-weight: bold; color: green; font-size: 25px;"><i class="el-icon-warning-outline"></i>
                路线预定事项</span>
            </div>

            <div style="padding: 10px;">
              <span class="textHead">【免费政策】</span>
              <div class="textBody">
                儿童：身高1.2米（不含）以下；
                老人：65周岁（含）以上凭老年证或身份证； 军人：凭有效证件；
                残疾人：凭有效证件。
              </div>
              <span class="textHead">【优惠政策】</span>
              <div class="textBody">
                儿童：身高1.2米（含）-1.4米（含）之间，儿童一定要在成年人的陪同下购票；
                老人：年龄60周岁（含）-65周岁（不含）之间凭有效证件，按生日计算年龄；
                学生：全日制大学本科及以下学历的本人有效学生证。
                以上信息仅供参考，具体以路线当日实际公示信息为准。
              </div>
              <span class="textHead"><i class="el-icon-magic-stick"></i>温馨提示</span>
              <br />
              <div class="textBody" style="padding-bottom: 20px;padding-right: 15px;">
                为保证购票顺利，预订时请务必填写真实姓名、手机号码等信息。
              </div>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import newAxios from "../../utils/axios";
export default {
  data() {
    return {
      title: "",
      imgUrl: "",
      price: 0.0,
      day: "",
      intro: "",
      setoffTime: 0,
      intro: "",
      endSite: "",
      startSite: "",
      isCollect: false,
      title: "",
      isCollect: false,
      myInfo: {},
      otherImgList:[],
    };
  },
  created() {
    this.getHotelData();
    this.Collect();
    this.getUser();
  },

  methods: {
    getUser() {
      newAxios
        .get("/admin/findUserById")
        .then((res) => res.data)
        .then((res) => {
          if (res.code == 200) {
            console.log(res.data);
            this.myInfo = res.data;
          }
        })
        .catch((err) => {
          // this.$message = "正在加载ing...有事请留言";
          console.log(err);
        });
    },
    back() {
      // this.$router.back();
      // this.$router.go(-1);
      window.history.back();
    },
    toSpotOrder() {
      if (Object.keys(this.myInfo).length > 0) {
        this.$router.push({
          path: "/routeOrder",
          query: {
            routeId: this.$route.query.routeId,
            price: this.price,
          },
        });
      } else {
        this.$message.error("请先登录！");
      }
    },
    //判断是否收藏
    Collect() {
      newAxios
        .get("/collection/isCollection", {
          params: {
            productId: parseInt(this.$route.query.routeId),
            productType: 2,
          },
        })
        .then((res) => res.data)
        .then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.isCollect = res.data;
            this.getHotelData();
            //   this.$message.success("收藏成功");
          } else {
            this.isCollect = res.data;
            this.getHotelData();
            //   this.$message.success("取消收藏成功");
          }
        });
    },
    //收藏

    collected() {
      newAxios
        .post("/collection/save", {
          productId: parseInt(this.$route.query.routeId),
          productType: 2,
          title: this.title,
        })
        .then((res) => res.data)
        .then((res) => {
          console.log(res.data);
          if (res.code == 200) {
            this.Collect();
            this.getHotelData();
            if (res.data == true) {
              this.$message({
                message: '收藏成功',
                type: 'success'
              })
            } else {
              this.$message({
                message: '收藏取消',
                type: 'warning'
              })
            }
          } else {
            this.Collect();
            this.getHotelData();
          }
        });
    },

    getHotelData() {
      console.log(this.$route.query.routeId);
      newAxios
        .get("/travelRoute/findById", {
          params: {
            id: this.$route.query.routeId,
          },
        })
        .then((res) => {
          console.log(res.data.data);
          this.title = res.data.data.title;
          this.imgUrl = res.data.data.imgUrl;
          this.startSite = res.data.data.startSite;
          this.endSite = res.data.data.endSite;
          this.price = res.data.data.price;
          this.day = res.data.data.day;
          this.intro = res.data.data.intro;
          this.startTime = res.data.data.startTime;
          this.endTime = res.data.data.endTime;
          this.title = res.data.data.title;
          this.otherImgList = res.data.data.otherUrl.split(",");
        });
    },
  },
};
</script>

<style>
.text {
  font-size: 14px;
}

.textHead {
   margin: 10px 0;
}

.textBody {
  width: 100%;
  line-height: 25px;
  font-size: 18px;
  padding: 10px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
}

.item {}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
